# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gst-plugins-good
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
         "${MINGW_PACKAGE_PREFIX}-gst-plugin-gtk")
pkgver=1.22.5
pkgrel=2
pkgdesc="GStreamer Multimedia Framework Base Plugins (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://gstreamer.freedesktop.org/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk3"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
              $([[ "${CARCH}" != "i686" && "${CARCH}" != "x86_64" ]] \
                || echo "${MINGW_PACKAGE_PREFIX}-nasm")
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-flac"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
         "${MINGW_PACKAGE_PREFIX}-lame"
         "${MINGW_PACKAGE_PREFIX}-libcaca"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libshout"
         "${MINGW_PACKAGE_PREFIX}-libsoup3"
         "${MINGW_PACKAGE_PREFIX}-libvpx"
         "${MINGW_PACKAGE_PREFIX}-mpg123"
         "${MINGW_PACKAGE_PREFIX}-speex"
         "${MINGW_PACKAGE_PREFIX}-taglib"
         "${MINGW_PACKAGE_PREFIX}-twolame"
         "${MINGW_PACKAGE_PREFIX}-wavpack"
         "${MINGW_PACKAGE_PREFIX}-zlib")
conflicts=("${MINGW_PACKAGE_PREFIX}-gst-plugins-ugly<1.22.0"
           "${MINGW_PACKAGE_PREFIX}-gst-plugins-bad<1.16.0")
source=("${url}/src/${_realname}/${_realname}-${pkgver}.tar.xz"{,.asc})
sha256sums=('b67b31313a54c6929b82969d41d3cfdf2f58db573fb5f491e6bba5d84aea0778'
            'SKIP')
validpgpkeys=('D637032E45B8C6585B9456565D2EEE6F6F349D7C') # Tim Müller <tim@gstreamer-foundation.org>

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    --buildtype plain \
    --wrap-mode=nofallback \
    -Dauto_features=enabled \
    -Dpackage-origin='https://www.msys2.org' \
    -Doss=disabled \
    -Doss4=disabled \
    -Dosxaudio=disabled \
    -Dosxvideo=disabled \
    -Dpulse=disabled \
    -Dqt5=disabled \
    -Dqt6=disabled \
    -Dv4l2=disabled \
    -Dximagesrc=disabled \
    -Daalib=disabled \
    -Djack=disabled \
    -Ddv=disabled \
    -Ddv1394=disabled \
    -Drpicamsrc=disabled \
    -Ddoc=disabled \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/ninja.exe
}

package_gst-plugins-good() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/ninja.exe install

  rm -f ${pkgdir}${MINGW_PREFIX}/lib/gstreamer*/*.a

  mkdir -p plugin-gtk/lib/gstreamer-1.0/
  mv "${pkgdir}${MINGW_PREFIX}/lib/gstreamer-1.0/libgstgtk.dll" plugin-gtk/lib/gstreamer-1.0/
}

package_gst-plugin-gtk() {
  pkgdesc+=" (gtk plugin)"
  depends=("${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
           "${MINGW_PACKAGE_PREFIX}-gtk3")

  cd "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${pkgdir}${MINGW_PREFIX}"
  mv plugin-gtk/* "${pkgdir}${MINGW_PREFIX}"
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :

# generate wrappers
for _name in "${pkgname[@]}"; do
  _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
  _func="$(declare -f "${_short}")"
  eval "${_func/#${_short}/package_${_name}}"
done
# template end;
